﻿using UnityEngine;
using System.Collections;

public class LoginWindow : BaseWindow
{
    //开始
    Transform mBtnStart;

    enum LOGINUI
    {
        None = -1,
        Login,
        SelectServer,
    }

    public LoginWindow()
    {
        //场景类型
        mScenesType = EScenesType.EST_Login;
        //场景资源
        mResName = GameConstDefine.LoadGameLoginUI;
        //是否常驻内存
        mResident = false;
    }

    ////////////////////////////继承接口/////////////////////////
    //类对象初始化监听显示和隐藏，为了解耦合
    public override void Init()
    {
        EventCenter.AddListener(EGameEvent.eGameEvent_LoginEnter, Show);
        EventCenter.AddListener(EGameEvent.eGameEvent_LoginExit, Hide);
    }

    //类对象释放
    public override void Realse()
    {
        EventCenter.RemoveListener(EGameEvent.eGameEvent_LoginEnter, Show);
        EventCenter.RemoveListener(EGameEvent.eGameEvent_LoginExit, Hide);
    }

    //窗口控件初始化以及控件监听
    protected override void InitWidget()
    {
        mBtnStart = mRoot.Find("BtnStart");
        mBtnStart.GetComponent<Button>().onClick.AddListener(OnClickAddButton);

        DestroyOtherUI();
    }

    //消息回调函数
    private void OnClickAddButton()
    {
        //在这里监听按钮的点击事件
        LoginCtrl.Instance.StartGame();
    }

    //删除Login外其他控件，例如
    public static void DestroyOtherUI()
    {
        Canvas canvas = GameMethod.GetCanvas;
        for (int i = 0; i < canvas.transform.childCount; i++)
        {
            if (canvas.transform.GetChild(i) != null && canvas.transform.GetChild(i).gameObject != null)
            {

                GameObject obj = canvas.transform.GetChild(i).gameObject;
                if (obj.name != "Login(Clone)")
                {
                    GameObject.DestroyImmediate(obj);
                }
            }
        }
    }

    //窗口控件释放
    protected override void RealseWidget()
    {
    }

    //游戏事件注册
    protected override void OnAddListener()
    {

    }

    //游戏事件注消
    protected override void OnRemoveListener()
    {

    }

    //显示
    public override void OnEnable()
    {

    }

    //隐藏
    public override void OnDisable()
    {
    }
}
